package com.espirit.common;

import java.util.Collection;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.googlecode.cswish.annotation.GenericType;
import com.googlecode.cswish.annotation.ParamScope;
import com.googlecode.cswish.annotation.Rest;
import com.googlecode.cswish.model.PageElement;
import com.googlecode.cswish.model.PageElements;
import com.googlecode.cswish.struts.spring.GenericService;

@Service
public class PPMessageService {
	
	@Resource
	private GenericService genericService;
	
	@Rest(simpleServiceName="espirit.common.message", type="_update")
	public void _update(@GenericType Object model,@ParamScope(visible=false, value="#ps")PageElements ps) {
    	if (model == null) return ;
    	Map map = ps.getAllElements();
		Collection<PageElement> pageElements = ps.getAllElements().values();
		for(PageElement pe : pageElements){
			if (!"hidden".equals(pe.getType())) {				
				pe.setTextModel(Boolean.TRUE);
			}
		}
		ps.addExtraParams("disableButtonArea", true);
		genericService.view(model);
    	
    }
	
	@Rest(simpleServiceName="espirit.common.message", type="_add")
	public void _add(@ParamScope(visible=false, value="#ps")PageElements ps) {
    	ps.getElement("model.title").setRequired(true);
    	ps.getElement("model.to.id").setRequired(true);
    }

}
